package us.norepeter.processing.textmatcher.names;

import us.norepeter.processing.textmatcher.AbstractTransformer;

/**
 * Detects if an Element has a property "lastName." If it does, detects
 * if the value of that property contains some kind of hyphen. If it does, 
 * then the name before the hyphen is put in property "lastName" and the
 * name after the hyphen is put in property "secondLastName". If it does
 * not then the original lastName remains unchanged and no secondLastName
 * property is inserted in the Element.
 * 
 * @author ##author##
 */
public class HyphenatedLastNameTransformer extends AbstractTransformer {

	HyphenatedLastNameTransformer() {
		super("HyphenatedLastNameTransformer", "lastName", "secondLastName");
	}

	@Override
	public SplitTransformation splitTransformation(String s) {
		String before, after;
		before = s;
		after = "";
		char[] typesOfHyphens = new char[] { '\u00AD', '\u2013', '\u2012', '\u2014', '\u2015' };
		for (char hyphen : typesOfHyphens) {
			String[] strs = s.split(String.valueOf(hyphen));
			if (strs != null && s.length() == 2) {
				before = strs[0];
				after = strs[1];
				return new SplitTransformation(before, after);
			}
		}
		return new SplitTransformation(before, after);
	}

}
